package some.black.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import some.black.dao.BlackDao;
import some.black.domain.BlackCommand;

@Controller
public class ReportController {
	
	@Autowired
	private BlackDao blackDao;
	
	@RequestMapping(value="pop_upReport.do",method=RequestMethod.GET)
	public ModelAndView form(@RequestParam("p_id") String p_id,HttpSession session){
		
		String id = (String)session.getAttribute("id");
		ModelAndView mav = new ModelAndView();
		mav.setViewName("pop_upReport");
		mav.addObject("p_id",p_id);
		mav.addObject("id",id);
		mav.addObject("success",0);
		return mav;
	}
	
	@RequestMapping(value="pop_upReport.do",method=RequestMethod.POST)
	public ModelAndView process(BlackCommand blackCommand,HttpSession session){
		
		String id = (String)session.getAttribute("id");
		
		blackCommand.setVictim(id);
		blackDao.insertBlack(blackCommand);
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("pop_upReport");
		mav.addObject("success",1);
		
		return mav;
	}
}
